package com.itheima.algorithm.hashtable;

/**
 * @author: TylerZhong
 * @description: 字符串中的第一个不重复字符
 */
public class E07Leetcode387 {

    /**
     示例 1：

     输入: s = "leetcode"
     输出: 0
     示例 2:

     输入: s = "loveleetcode"
     输出: 2
     示例 3:

     输入: s = "aabb"
     输出: -1
     * @param s
     * @return
     */
    public int firstUniqChar(String s) {
        int[] array = new int[26];
        char[] chars = s.toCharArray();
        for (char ch : chars) {
            array[ch - 'a']++;
        }
        for (int i = 0; i < chars.length; i++) {
            if (array[chars[i] - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }
}
